c_scheds = ['scx_simple', 'scx_qmap', 'scx_central', 'scx_userland', 'scx_nest',
            'scx_flatcg', 'scx_pair', 'scx_prev', 'scx_even_cpu', 'scx_hello']

c_scheds_lib = ['scx_sdt']

thread_dep = dependency('threads')

# 添加libkperf依赖
libkperf_inc = include_directories('/usr/local/include/libkperf')
libkperf_lib = meson.get_compiler('cpp').find_library('kperf', dirs: ['/usr/local/lib/libkperf'])
libsym_lib = meson.get_compiler('cpp').find_library('sym', dirs: ['/usr/local/lib/libkperf'])

foreach sched: c_scheds
  bpf_o = gen_bpf_o.process(sched + '.bpf.c')
  bpf_skel = gen_bpf_skel.process(bpf_o)
  
  # 为scx_hello添加libkperf依赖
  if sched == 'scx_hello'
    executable(sched, [bpf_skel, sched + '.c'],
               include_directories: [user_c_includes, libkperf_inc],
               dependencies: [kernel_dep, libbpf_dep, thread_dep, libkperf_lib, libsym_lib],
               install: true)
  else
    executable(sched, [bpf_skel, sched + '.c'],
               include_directories: [user_c_includes],
               dependencies: [kernel_dep, libbpf_dep, thread_dep],
               install: true)
  endif
endforeach

foreach sched: c_scheds_lib
  bpf_o = gen_bpf_o.process(sched + '.bpf.c')
  bpf_skel = gen_bpf_skel_lib.process(bpf_o)
  executable(sched, [bpf_skel, sched + '.c'],
             include_directories: [user_c_includes],
             dependencies: [kernel_dep, libbpf_dep, thread_dep],
             install: true)
endforeach
